<html>
        <head>
                <title>ResellersPanel</title>
                <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
                <style>
			body {
				background-attachment: scroll;
				background-position: top;
				background-repeat: repeat-x;
				background-color:#FFFFFF;
				font-family: Tahoma, Helvetica, sans-serif;
                                font-weight: none;
				font-size: 11px;
			}
                        th {
                                height: 20px;
                                background-image: url(images/bg_th.jpg);
                                background-position: top;
                                background-repeat: repeat-x;
                                font-family: Tahoma, Helvetica, sans-serif;
                                font-size: 11px;
                                font-weight: bold;
                                color: #FFFFFF;
                        }

						.bTable {
							padding: none;
							border-top:1px #FFC9AD solid;
							border-bottom:1px #FFC9AD solid;
							border-left:1px #FFC9AD solid;
							border-right:1px #FFC9AD solid;
						}
						
						.bTable tr:hover {
							background-color:#FEFDE2;
						}
						
						.bTable td {
								padding: 5px;
								border: none;
								font-size: 11px;
								font-family: Tahoma;
								color: #000000;
								text-decoration: none
						}
                        .bTable th {
                                padding: 2px;
                            /*    background-color:#E9E8E0;*/
                                background-color: white;
                                border: #FFC9AD solid;
                                        border-width: 0px 0px 1px 1px;
                                font-size: 11px;
                                font-weight: bold;
                                font-family: Tahoma, Helvetica, sans-serif;
                                color: #0F0F0F;
                                text-decoration: none;

                        }
                        .bTable table{
                                        border-color: #FFC9AD #FFC9AD #FFC9AD #FFC9AD;
                                 border-style: solid;
                                 border-top-width: 1px;
                                 border-right-width: 1px;
                                 border-bottom-width: 0px;
                                 border-left-width: 0px;
                        }
                        .bTable td td {
                                border: 0px;
                                border-bottom: 1px solid;
                                        border-left-width: 1px solid;
                                        border-left-color:#FFC9AD;
                                border-bottom-color:#FFC9AD;
                        }
                        .errormsg{
                                        color: #FF0000;
                                font-size: 12pt;
                                font-family: Verdana, Arial, Helvetica, sans-serif;
                                width: 100%;
                                font-weight: bold;
                        }
                </style>
		<script>               
			function callOpener (url) {
				if (window.opener && !window.opener.closed) window.opener.location=url;
				else window.open(url,'subOpener','');
			}
		</script>
        </head>
        <body onLoad='window.focus();'>
<?
include('wallet_db.html');
include('../rp2/global_functions.php');
#include('multi_language.php');
$message1 = translate('message1');
$legend = translate('legend');
$username_th = translate('username');
$accounts_th = translate('accounts');
$accounts2expire = translate('accounts2expire');
$accounts_active = translate('accounts_active');
$accounts_expired = translate('accounts_expired');
$accounts_total = translate('accounts_total');
$change_link = translate('change_link');
$domains_th = translate('domains');
$domains2expire = translate('domains2expire');
$domains_active = translate('domains_active');
$domains_expired = translate('domains_expired');
$domains_total = translate('domains_total');
$expire_date_th = translate('expire_date');
$login_link = translate('login_link');
$number_th = translate('number');
$plan_th = translate('plan');
$rp_th = translate('rp');
$server_th = translate('server');
$start_date_th = translate('start_date');
$wp_th = translate('wp');
$dberror = translate('dberror');
$users = translate('users');
$close_window = translate('close_window');
if (!isset($rid) or !isset($pid)) {
        echo "<div class=errormsg>No plan selected!</div>";
} else {
	$order_cl = 'ORDER BY username ASC';
	if (!isset($by)) $by = 'username_asc';
	switch ($by) {
		case 'username_desc':
			$order_cl = 'ORDER BY username DESC';
			break;
		case 'username_asc':
			$order_cl = 'ORDER BY username ASC';
			break;
		case 'start_d_desc':
			$order_cl = 'ORDER BY start_date DESC';
			break;
		case 'start_d_asc':
			$order_cl = 'ORDER BY start_date ASC';
			break;
		case 'expire_desc':
			$order_cl = 'ORDER BY expire_date DESC';
			break;
		case 'expire_asc':
			$order_cl = 'ORDER BY expire_date ASC';
			break;
		case 'server_asc':
			$order_cl = 'ORDER BY server ASC';
			break;
		case 'server_desc':
			$order_cl = 'ORDER BY server DESC';
			break;
	}
	if ($order_cl == 'ORDER BY username DESC') {
	#	echo "desc<br>";
	} elseif ($order_cl == 'ORDER BY username ASC') {
	#	echo "asc<br>";
	} else {
	#	echo "none<br>";
	}
        //-----------------------------------------------------
                $sql['type'] = "SELECT";
                $sql['params'] = "c.client_id, c.username, pu.start_date, pu.expire_date, c.server,pr.name,pr.wholesale,pr.price";
                $sql['table'] = "purchases as pu, products as pr, clients as c";
                $sql['where'] = "pu.product_id='$pid' and pu.product_id = pr.product_id and pu.client_id=c.client_id and c.blocked=0 and pu.start_date is not null and pu.expire_date is not null";
                $sql['options'] = "$order_cl";
                $sql['return'] = "query";
                $sql['return'] = "struct";
        //------------------------------------------------------
	#echo $result=sql_exec($sql,$dbh81,'assoc');
        if (!$result=sql_exec($sql,$dbh81,'assoc')) {
                exit("$dberror");
        }
	$pl_name = $result[0]['name'];
	echo "$message1<br>";
	echo "<div align=left><b>$pl_name</b> $users</div><br>";
	echo "<TABLE class='bTable' cellspacing=0>
	<tr>";
		$params['sid'] = $sid;
		$params['action'] = 'showPlanClientsDetails';
		$params['order'] = 'yes';
		$params['rid'] = $rid;
		$params['pid'] = $pid;
		if ($by == 'username_asc') {
			$params['by'] = 'username_desc';
		} else {
			$params['by'] = 'username_asc';
		}
		$tmpurl = "$baseURL/?".encode_params($params);
		echo "<th><a href='$tmpurl'>$username_th</a></th>";
		unset($params,$tmpurl);
		
		$params['sid'] = $sid;
		$params['action'] = 'showPlanClientsDetails';
		$params['order'] = 'yes';
		$params['rid'] = $rid;
		$params['pid'] = $pid;
		if ($by == 'start_d_asc') {
			$params['by'] = 'start_d_desc';
		} else {
			$params['by'] = 'start_d_asc';
		}
		$tmpurl = "$baseURL/?".encode_params($params);
		echo "<th><a href='$tmpurl'>$start_date_th</a></th>";
		unset($params,$tmpurl);
		
		$params['sid'] = $sid;
		$params['action'] = 'showPlanClientsDetails';
		$params['order'] = 'yes';
		$params['rid'] = $rid;
		$params['pid'] = $pid;
		if ($by == 'expire_asc') {
			$params['by'] = 'expire_desc';
		} else {
			$params['by'] = 'expire_asc';
		}
		$tmpurl = "$baseURL/?".encode_params($params);
		echo "<th><a href='$tmpurl'>$expire_date_th</a></th>";
		unset($params,$tmpurl);

		$params['sid'] = $sid;
		$params['action'] = 'showPlanClientsDetails';
		$params['order'] = 'yes';
		$params['rid'] = $rid;
		$params['pid'] = $pid;
		if ($by == 'server_asc') {
			$params['by'] = 'server_desc';
		} else {
			$params['by'] = 'server_asc';
		}
		$tmpurl = "$baseURL/?".encode_params($params);
		echo "<th><a href='$tmpurl'>$server_th</a></th>
		<th>$wp_th</th>
		<th>$rp_th</th>
		<th>&nbsp;</th>
		<th>$plan_th</th>
	</tr>";
	unset($params,$tmpurl);
	$acct_expired = '0';
	$acct_expired_wsp = '0.00';
	$acct_expired_retp = '0.00';
	$acct_ab_expired = '0';
	$acct_ab_expired_wsp = '0.00';
	$acct_ab_expired_retp = '0.00';
	$acct_active = '0';
	$acct_active_wsp = '0.00';
	$acct_active_retp = '0.00';

	$dom_expired = '0';
	$dom_expired_wsp = '0.00';
	$dom_expired_retp = '0.00';
	$dom_ab_expired = '0';
	$dom_ab_expired_wsp = '0.00';
	$dom_ab_expired_retp = '0.00';
	$dom_active = '0';
	$dom_active_wsp = '0.00';
	$dom_active_retp = '0.00';

	foreach ($result as $value) {
		//-----------------------------------------------------
                	$sql['type'] = "SELECT";
               		$sql['params'] = "(d.sld||'.'||d.tld) as domain, pu.start_date, pu.expire_date,pr.price,pr.wholesale";
                	$sql['table'] = "registerdomain as d, purchases as pu, clients as c,products as pr";
                	$sql['where'] = "c.username='".$value['username']."' and c.client_id=pu.client_id and pu.product_id=pr.product_id and pu.purchase_id=d.purchase_id";
                	$sql['options'] = "";
                	$sql['return'] = "query";
                	$sql['return'] = "struct";
        	//------------------------------------------------------
        	# exit($res=sql_exec($sql,$dbh81,'assoc'));
        	$res=sql_exec($sql,$dbh81,'assoc');
		unset($domains,$start,$end,$dom_price,$dom_whole);
		$now_date = strtotime(date('d-M-Y'));
		if (!empty($res)) {
			foreach ($res as $vl) {
				unset($start_date,$exp_date,$dom,$font,$after_14_days,$dom_wsp,$dom_retp);
				$dom_wsp = $vl['wholesale'][12]['USD'];
				$dom_retp = $vl['price'][12]['USD'];
				$start_date = strtotime(date('d-M-Y',strtotime($vl['start_date'])));
				$exp_date = strtotime($vl['expire_date']);
				$after_14_days = strtotime("-14 days",strtotime($vl['expire_date']));
				$dom = $vl['domain'];
				if ($exp_date <= $now_date) {
					$font = "<font color='#FF0000'>";
					$dom_expired ++;
                        		$dom_expired_wsp += $dom_wsp;
                        		$dom_expired_retp += $dom_retp;
				} elseif ($now_date >= $after_14_days) {
					$font = "<font color='#FFCC66'>";
					$dom_ab_expired ++;
		                        $dom_ab_expired_wsp += $dom_wsp;
                		        $dom_ab_expired_retp += $dom_retp;

				} else {
					$font = "<font color='#000000'>";
                        		$dom_active ++;
                        		$dom_active_wsp += $dom_wsp;
                        		$dom_active_retp += $dom_retp;
				}
				$domains .= "&nbsp;".$font.$vl['domain']."</font><br>";
				$start .= date('d-M-Y',strtotime($vl['start_date']))."<br>";
				$end .= $font.date('d-M-Y',strtotime($vl['expire_date']))."</font><br>";
				$dom_price .= $font."$".$vl['price'][12]['USD']."</font><br>";
				$dom_whole .= $font."$".$vl['wholesale'][12]['USD']."</font><br>";
			}
		}
		$params[sid]=$sid;
	        $params[action]='client_login';
		$params[client]=$value['username'];
		$url="$baseURL/?".encode_params($params);
		$url=htmlentities($url);

		unset($start_date,$exp_date,$dom,$font,$after_14_days,$wsp,$retp);
		$wsp = $value['wholesale'][12]['USD'];
		$retp = $value['price'][12]['USD'];
		$start_date = strtotime($value['start_date']);
		$exp_date = strtotime($value['expire_date']);
		$after_14_days = strtotime("-14 days",strtotime($value['expire_date']));
		if ($exp_date <= $now_date) {
			$font = "<font color='#FF0000'>";
			$acct_expired ++;
			$acct_expired_wsp += $wsp;
			$acct_expired_retp += $retp;
		} elseif ($now_date >= $after_14_days) {
			$font = "<font color='#FFCC66'>";
			$acct_ab_expired ++;
			$acct_ab_expired_wsp += $wsp;
			$acct_ab_expired_retp += $retp;
		} else {
			$font = "<font color='#000000'>";
			$acct_active ++;
			$acct_active_wsp += $wsp;
			$acct_active_retp += $retp;
		}

		echo "<tr>
		<td><b>".$font.$value['username']."</font></b><br>$domains</td>
		<td>".date('d-M-Y',strtotime($value['start_date']))."<br>$start</td>
		<td>".$font.date('d-M-Y',strtotime($value['expire_date']))."</font><br>$end</td>
		<td>".$value['server']."</td>
		<td align='right'>".$font."$".$wsp."</font><br>$dom_whole</td>
		<td align='right'>".$font."$".$retp."</font><br>$dom_price</td>
		<td><a href='$url' target='_blank'>$login_link</a></td>";
		unset($params);
		$params[sid]=$sid;
		$params[action]='moveClient2Plan';
		$params[step2]='345';
		$params[client_id]=$value['client_id'];
		$moveplanurl="$baseURL/$webDIR/?".encode_params($params);
		echo "<td><a href='#' onClick=\"callOpener('$moveplanurl');\">$change_link</a></td>
	</tr>";
	}
	$acct_total = $acct_ab_expired + $acct_expired + $acct_active;
	$acct_total_wsp = $acct_ab_expired_wsp + $acct_expired_wsp + $acct_active_wsp;
	$acct_total_retp = $acct_ab_expired_retp + $acct_expired_retp + $acct_active_retp;

	$dom_total = $dom_ab_expired + $dom_expired + $dom_active;
	$dom_total_wsp = $dom_ab_expired_wsp + $dom_expired_wsp + $dom_active_wsp;
	$dom_total_retp = $dom_ab_expired_retp + $dom_expired_retp + $dom_active_retp;

	
        echo "</table><br><br>
	<TABLE class='bTable' cellspacing=0>
	<tr>
		<th>$accounts_th</th>
		<th>$number_th</th>
		<th>$wp_th</th>
		<th>$rp_th</th>
	</tr>
	<tr>
		<td><font color='#FFCC66'>$accounts2expire</font></td>
		<td align='right'><font color='#FFCC66'>$acct_ab_expired</font></td>
		<td align='right'><font color='#FFCC66'>$".number_format($acct_ab_expired_wsp,2,'.',',')."</font></td>
		<td align='right'><font color='#FFCC66'>$".number_format($acct_ab_expired_retp,2,'.',',')."</font></td>
	</tr>
	<tr>
		<td><font color='#FF0000'>$accounts_expired</font></td>
		<td align='right'><font color='#FF0000'>$acct_expired</font></td>
		<td align='right'><font color='#FF0000'>$".number_format($acct_expired_wsp,2,'.',',')."</font></td>
		<td align='right'><font color='#FF0000'>$".number_format($acct_expired_retp,2,'.',',')."</font></td>
	</tr>
	<tr>
		<td>$accounts_active</td>
		<td align='right'>$acct_active</td>
		<td align='right'>$".number_format($acct_active_wsp,2,'.',',')."</td>
		<td align='right'>$".number_format($acct_active_retp,2,'.',',')."</td>
	</tr>
	<tr>
		<td><b>$accounts_total</b></td>
		<td align='right'><b>$acct_total</b></td>
		<td align='right'><b>$".number_format($acct_total_wsp,2,'.',',')."</b></td>
		<td align='right'><b>$".number_format($acct_total_retp,2,'.',',')."</b></td>
	</tr>
	</table><br><br>
	<TABLE class='bTable' cellspacing=0>
	<tr>
		<th>$domains_th</th>
		<th>$number_th</th>
		<th>$wp_th</th>
		<th>$rp_th</th>
	</tr>
	<tr>
		<td><font color='#FFCC66'>$domains2expire</font></td>
		<td align='right'><font color='#FFCC66'>$dom_ab_expired</font></td>
		<td align='right'><font color='#FFCC66'>$".number_format($dom_ab_expired_wsp,2,'.',',')."</font></td>
		<td align='right'><font color='#FFCC66'>$".number_format($dom_ab_expired_retp,2,'.',',')."</font></td>
	</tr>
	<tr>
		<td><font color='#FF0000'>$domains_expired<font></td>
		<td align='right'><font color='#FF0000'>$dom_expired</font></td>
		<td align='right'><font color='#FF0000'>$".number_format($dom_expired_wsp,2,'.',',')."</font></td>
		<td align='right'><font color='#FF0000'>$".number_format($dom_expired_retp,2,'.',',')."</font></td>
	</tr>
	<tr>
		<td>$domains_active</td>
		<td align='right'>$dom_active</td>
		<td align='right'>$".number_format($dom_active_wsp,2,'.',',')."</td>
		<td align='right'>$".number_format($dom_active_retp,2,'.',',')."</td>
	</tr>
	<tr>
		<td><b>$domains_total</b></td>
		<td align='right'><b>$dom_total</b></td>
		<td align='right'><b>$".number_format($dom_total_wsp,2,'.',',')."</b></td>
		<td align='right'><b>$".number_format($dom_total_retp,2,'.',',')."</b></td>
	</tr>
	</table><br><br>";
	echo $legend."<br>";
}
?>
	[<a href='#' onclick="window.close();">CLOSE THE WINDOW</a>]&nbsp;
	[<a href='#' onclick="window.print();">PRINT THE WINDOW</a>]
        </body>
</html>
